// A attempt to find some particular lines...;
import java.util.ArrayList; 
import java.io.PrintStream;
import java.util.Random;
import java.util.ArrayList;
import utils.*; 
public class Steiner2 {
	
	public static void main(String[] args) throws Exception{
		PrintStream output=new PrintStream("outSTEINER.txt");
		ArrayList<Sphere> allSpheres=new ArrayList<Sphere>(); 
		String couleurs[]={"Blue","Yellow","Green","Red","White","MediumSlateBlue","Orange","MediumOrchid"};
		
		Random gene=new Random();
		
		output.println("#declare steiner=union{");
		
		// t=0 r varying from 0 to 1
		int steps=100; 
		int stepsj=7; 
		for(int j=0;j<stepsj;j++ ){
			double r=(0.0+j)/stepsj; 
		for(int i=0;i<steps;i++){
			
			double t=2*Math.PI*i/steps; 
			double x=r*r*Math.sin(t)*Math.cos(t); 
			double y=r*Math.sin(t)*Math.sqrt(1-r*r); 
			double z=r*Math.cos(t)*Math.sqrt(1-r*r); 
			
			Sphere sp=new Sphere(x,y,z,0.02,couleurs[j]);
			double minradius=0.02;
			double radius=minradius; 
			for(Sphere spc:allSpheres){
				if(sp.intersects(spc)) {
						radius=spc.distance(sp)-spc.getRadius();
						//if(radius<0){System.out.println(radius); System.exit(0); }
						if(radius<minradius)minradius=radius; 
					
				}
				sp.setRadius(minradius); 
			
			}
			if(sp.getRadius()>0.00001)
			allSpheres.add(sp);		
		
			
		}
		}// for j	
			
			

			
			
			
			
		
		
		
		for(int i=0;i<200000;i++){

		
			double r=gene.nextDouble();
			double t=Math.PI*2*gene.nextDouble(); 
			
			double x=r*r*Math.sin(t)*Math.cos(t); 
			double y=r*Math.sin(t)*Math.sqrt(1-r*r); 
			double z=r*Math.cos(t)*Math.sqrt(1-r*r); 
			
			Sphere sp=new Sphere(x,y,z,0.01);
			double minradius=0.01;
			double radius=minradius; 
			for(Sphere spc:allSpheres){
				if(sp.intersects(spc)) {
						radius=spc.distance(sp)-spc.getRadius();
						//if(radius<0){System.out.println(radius); System.exit(0); }
						if(radius<minradius)minradius=radius; 
					
				}
				sp.setRadius(minradius); 
			
			}
			if(sp.getRadius()>0.00001)
			allSpheres.add(sp);		
		
			if(i%1000==0) System.out.println(i);
		}
		for(Sphere sp:allSpheres) {
			output.println(sp);
			System.out.println(sp); 
		}
		System.out.println(allSpheres.size()); 
		output.println("}");
		System.out.println("done"); 
		
		
	}
	
	

}
